// 统一的API响应结构
export interface APIResponse<T = any> {
  code: number
  msg: string
  data?: T
}

// 成功响应
export interface SuccessResponse<T = any> {
  code: 0
  msg: string
  data: T
}

// 错误响应
export interface ErrorResponse extends APIResponse {
  code: number // 非0
  msg: string
  data?: any
}

// 通用响应类型
export type Response<T = any> = SuccessResponse<T> | ErrorResponse

// 判断是否为成功响应
export function isSuccess<T = any>(response: Response<T>): response is SuccessResponse<T> {
  return response.code === 0
}

// 判断是否为错误响应
export function isError(response: Response): response is ErrorResponse {
  return response.code !== 0
} 